<template>
  <div class="shop">
    <el-row :gutter="10">
      <el-col :span="24">
        <el-card class="box-card">
          <!-- 头部 -->
          <div slot="header" class="clearfix fix-lh">
            <span>店铺管理</span>
            <div class="btn-list">
              <el-button size="mini" @click="handleAdd" v-hasPermission="permission.add">新增</el-button>
            </div>
          </div>
          <div class="home-body">
            <cvue-table
              :option="tableOption"
              :data="tableData"
              ref="tbl1"
              :isShowAdd="false"
              :page="page"
              :tablePage="tablePage"
              :pageSize="page.pageSize"
              :loading="tableLoading"
              @current-change="handleCurrentChange"
              @size-change="handleSizeChange"
              :isShowPage="false">
              <template slot-scope="scope" slot="flagship">
                <span>{{ scope.row.flagship === 0 ? '自定义' : '旗舰店' }}</span>
              </template>
              <!-- 操作按钮 -->
              <el-table-column fixed="right" slot="actionMenu" label="操作" align="center" header-align="center" width="160">
                <template slot-scope="scope">
                  <el-button type="text" size="small" @click="handleEdit(scope.row)" v-hasPermission="permission.edit">修改</el-button>
                  <el-button type="text" size="small" @click="handleDelete(scope.row)" v-hasPermission="permission.delete">删除</el-button>
                </template>
              </el-table-column>
            </cvue-table>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
import cvueTable from '@/components/cvue-table'
import {getClientHeight} from '@/util/tool'
export default {
  name: 'shop-manage1',
  components: {
    cvueTable
  },
  data () {
    return {
      tablePage: 1,
      tableLoading: false,
      page: {
        total: 1, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10, // 每页显示多少条
        pageSizes: [10, 50, 100]
      },
      tableOption: {
        stripe: true,
        width: '100%',
        border: true,
        index: false,
        selected: false,
        cloumn: [
          { prop: 'index', label: '', align: 'center', width: 58 },
          { prop: 'storeName', label: '名称', align: 'center', sortable: true },
          { prop: 'flagship', label: '创建类型', align: 'center', sortable: true, slotStatus: true },
          { prop: 'createTime', label: '创建时间', align: 'center', sortable: true },
          { prop: 'updateTime', label: '更新时间', align: 'center', sortable: true }
        ]
      },
      tableData: [
        // { name: 'ddd', code: 'sss', order: 1, status: 1 }
      ],
      dialogIndexEdit: false,
      actionType: 'add',
      rowData: {},
      name: '',
      selectName: ''
    }
  },
  computed: {
    height () {
      var height = getClientHeight() - 170
      return height + 'px'
    },
    isDelete () {
      return this.selectIds.indexOf(this.userInfo.id) > -1
    },
    ...mapGetters(['token', 'userInfo'])
  },
  mounted () {
    this.handleList(this.selectName)
  },
  methods: {
    // 新增
    handleAdd () {
      this.actionType = 'add'
      var item = {
        value: '/home/shop-edit'
      }
      this.$store.commit('common/CLOSE_TAG', item)
      this.$nextTick(() => {
        this.$router.push({path: '/home/shop-edit', query: {action: 'add'}})
      })
    },
    // 编辑
    handleEdit (row) {
      this.actionType = 'edit'
      this.$router.push({path: '/home/shop-edit', query: {action: 'edit', id: row.id}})
      // this.rowData = row
    },
    handleDelete (row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var params = {
          id: row.id
        }
        this.$store.dispatch('manage/StoreRemove', params).then(res => {
          this.$message({
            type: 'success',
            message: res.msg
          })
          this.tablePage = 1
          this.handleList(this.selectName)
        }).catch((err) => {
          this.$message({type: 'error', message: err.msg})
        })
      }).catch(() => {
      })
    },
    // 改变pagesize
    handleSizeChange (val) {
      this.page.pageSize = val
      this.handleList(this.selectName)
    },
    // 改变页码
    handleCurrentChange (val) {
      this.tablePage = val
      this.handleList(this.selectName)
    },
    // 列表接口
    handleList () {
      this.tableLoading = true
      var params = {
        // page: this.tablePage,
        // limit: this.page.pageSize,
        // name: name
      }
      this.$store.dispatch('manage/StoreGet', params).then(res => {
        // console.log(res)
        var data = res.data
        this.tableData = data
        this.page.total = res.data.count
        this.page.currentPage = this.tablePage
        this.tableLoading = false
      }).catch(err => {
        console.log(err)
        this.tableLoading = false
      })
    },
    // 关闭弹窗
    closeDialog (params) {
      if (params == 'edit') {
        this.dialogIndexEdit = false
      }
    },
    // 确认
    confirmDialog (params) {
      if (params == 'edit') {
        this.dialogIndexEdit = false
        this.selectKey = ''
        this.selectValue = ''
        this.tablePage = 1
        this.handleList(this.selectName)
      }
    },
    handleSearch () {
      this.selectName = this.name
      this.tablePage = 1
      this.handleList(this.selectName)
    }
  }
}
</script>

<style lang="scss">
.shop {
  padding: 0px !important;
  height: auto !important;
  .btn-list {
    float: right;
    margin-right: 10px;
    font-size: 12px;
    color: #409EFF;
    cursor: pointer;
  }
  .el-card__header {
    border-bottom: none;
  }
  .el-card__header,
  .el-card__body {
    padding: 15px;
  }
  .fix-lh {
    line-height: 32px;
  }
  .el-input.is-disabled .el-input__inner {
    color: #606266;
  }
  .left{
    min-height:500px;
    background:#fff;
  }
  .left-tree{
    width: 100%;
    min-height:600px;
    overflow: auto;
  }
  .left-top{
    width: 100%;
    height: 40px;
    text-align: center;
    line-height: 40px;
    font-size: 16px;
    color: #333;
    background: #e2e2e2;
    font-size: 15px;
  }
}
</style>
